package panel.recommendPathList
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	import panel.viewSpots.navigation.ScrollTxtHor;
	
	import struct.RecommendPath;
	
	public class SysPathBox extends Sprite
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		public var info:RecommendPath;
		
		private var titleText:ScrollTxtHor;
		private var timeText:TextField;
		
		private var backgroud:Bitmap;
		
		private var leftIcon:Bitmap;
		private var rightIcon:Bitmap;
		
		private var cover:Sprite;
		
		public function SysPathBox(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null)
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			this.cacheAsBitmap = true;
			initThis();
		}
		
		private function initThis():void
		{	
			backgroud = new _loader.uiManager.componentBack as Bitmap;
			
			backgroud.width = _stage.stageWidth;
			backgroud.height = _stage.stageHeight * .15;
			this.addChild(backgroud);
			
			titleText = new ScrollTxtHor();
			titleText.mouseEnabled = true;
			titleText.showWid = _stage.stageWidth * .5;
//			titleText.selectable = false;
//			titleText.wordWrap = false;
//			titleText.multiline = false;
			this.addChild(titleText);
			titleText.x = 0;
			titleText.y = 20;
			
			timeText = new TextField;
			timeText.mouseEnabled = true;
			timeText.selectable = false;
			timeText.wordWrap = false;
			timeText.multiline = false;
			this.addChild(timeText);
			timeText.x = 0;
			timeText.y = backgroud.height - 20;
			
			leftIcon = new _loader.uiManager.pathGuideIcon as Bitmap;
			rightIcon = new _loader.uiManager.arrowIcon as Bitmap;
			repositionImg();
		}
		
		private function repositionImg():void
		{
			if(_stage){
				this.addChild(leftIcon);
				this.addChild(rightIcon);
				
				leftIcon.x = backgroud.height * .1;
				leftIcon.y = backgroud.height * .1;
				leftIcon.width = backgroud.height * .8;
				leftIcon.height = backgroud.height * .8;
				
				rightIcon.x = backgroud.width - rightIcon.width - backgroud.height * .1;
				rightIcon.y = (backgroud.height - rightIcon.height) / 2;
			}
		}
		
		public function changeData(obj:RecommendPath):void
		{
			info = obj;
			
//			TextFieldUtils.setHtmlText(titleText,"<b>" + HtmlText.formatSizeColor(obj.name,0x000000,20) + "</b>");
//			titleText.width = titleText.textWidth + 5;
//			titleText.height = titleText.textHeight + 5;
			
			titleText.label(HtmlText.formatSizeColor("<b>" + obj.name + "</b>",0x000000,20));
			
			TextFieldUtils.setHtmlText(timeText,HtmlText.formatSizeColor(_lang.client("需要天数",{num:obj.totalDays}),0x000000));
			timeText.width = timeText.textWidth + 5;
			timeText.height = timeText.textHeight + 5;
			
			titleText.x = backgroud.height  + 10;
			titleText.y = backgroud.height * .5 - titleText.height - 5;
			timeText.x = backgroud.height + 10;
			timeText.y = backgroud.height * .5 + 5;
			
			addCover();
		}
		
		private function addCover():void
		{
			if(cover == null){
				cover = new Sprite;

				cover.graphics.beginFill(0x000000,0);
				cover.graphics.drawRect(0,0,this.width,this.height);
				cover.graphics.endFill();
				
				this.addChild(cover);
			}
		}
		
		public function clear():void
		{
			if(_stage){
				_stage = null;
				_loader = null;
				_lang = null;
				_uri = null;
				
				this.removeChild(backgroud);
				backgroud = null;
				
				this.removeChild(titleText);
				titleText = null;
				
				this.removeChild(timeText);
				timeText = null;
				
				leftIcon = null;
				rightIcon = null;
				
				cover = null;
			}
		}
	}
}